/*
 * Settings.java
 *
 * Created on 02 September 2006, 14:44
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jhub;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;

/**
 *
 * @author root
 */
public class Settings extends Properties{
    
    public static enum PropertyKey {
        db_url,db_user,db_pass,hub_id,test_db_url,test_db_user,test_db_pass,test_hub_id
    };
    
    
    private static final String DEFAUL_FILE_NAME = "settings.xml";
    
    public Settings(String file) throws IOException {
        FileInputStream fis = new FileInputStream(file);
        this.loadFromXML(fis);
        this.list(System.out);
    }
    
    public Settings() throws IOException {
        this(DEFAUL_FILE_NAME);
    }
    
    public String getProperty(PropertyKey key){
        return this.getProperty(key.toString());
    }
    
    
    public static void makeDefault() throws FileNotFoundException, IOException{
        Properties prop = new Properties();
        prop.setProperty("db_url", "jdbc:postgresql://<database>");
        prop.setProperty("db_user", "<user>");
        prop.setProperty("db_pass", "<passwd>");
        prop.setProperty("hub_id", "1");
        
        FileOutputStream fos = new FileOutputStream(DEFAUL_FILE_NAME);
        prop.storeToXML(fos, "Settings", "ISO-8859-1");
        fos.close();
    }
}
